package com.example.tika.Utils;

import org.apache.tika.Tika;

/**
 * @author wwl
 * @version 1.0
 * @date 2024/3/15 10:56
 * @description:
 * 获取文件类型：
 * 开发文档：https://iowiki.com/tika/tika_extracting_pdf.html
 */
public class FileTypeDetector {
    public class FileTypeContant {

        public static final String FILE_TYPE_XLS = "application/vnd.ms-excel";
        public static final String FILE_TYPE_XLSX = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
        public static final String FILE_TYPE_DOC = "application/msword";
        public static final String FILE_TYPE_DOCX = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
        public static final String FILE_TYPE_PDF = "application/pdf";
        public static final String FILE_TYPE_JSON = "application/json";
        public static final String FILE_TYPE_XML = "application/xml";
        public static final String FILE_TYPE_PNG = "image/png";
        public static final String FILE_TYPE_SVG = "image/svg";

    }

    public static String getType(String url) {
        return new Tika().detect(url);
    }

    public static void main(String[] args) {
        String url = "C:\\Users\\Administrator\\Desktop\\个人\\阿里云并行环境.txt";
        System.out.println(FileTypeDetector.getType(url));
    }
}
